Single qubit
Contents
3.1. Single qubit#
Quantum computers store information in a two-dimensional Hilbert space called a qubit. In this section, I will introduce mathematical description of a single qubit.
Pure states#
In ideal situations, the state of a qubit is specified by a ket vector in a two-dimensional Hilbert space. Unless otherwise is specified, state vectors are assumed to be normalized. That is \(\langle \psi | \psi \rangle = 1\) (See Section 1.7). In less ideal situations, a qubit is in a mix state involving multiple state vectors, which will be discussed in a later chapter. In this chapter, we focus on pure states.
Any qubit state can be written as
where \(| 0 \rangle \) and \(| 1 \rangle\) are orthonormal basis vectors satisfying \(\langle 0 | 0 \rangle = \langle 1 | 1 \rangle = 1\) and \(\langle 0 | 1 \rangle = \langle 1 | 0 \rangle = 0\). The coefficients \(c_0\) and \(c_1\) are complex numbers. The normalization requirement is satisfied if \(|c_0|^2 + |c_1|^2 = 1\).
This orthonroaml complete basis set \(\{|0\rangle, |1\rangle\}\) is known as computational basis and it is a convention to use it in quantum computing. However, the basis vectors do not represent any particular physical basis set. In real quantum computers, a qubit can be realized, for example, by an electron spin, \(|0\rangle \equiv | \uparrow \rangle\) and \(|1\rangle \equiv |\downarrow \rangle\) or a polarization of photon, \(|0\rangle \equiv | H \rangle\) (horizontal polarization) and \(|1\rangle \equiv | V \rangle\) (vertical polarization). By using the computational basis set, we don’t have to worry about what type of hardware is used. The mathematical expression based on the computational basis can be applied to all of quantum computers based on qubits.
The basis sets in Qiskit#
In Qiskit, the basis sets \(\{|0\rangle, |1\rangle\}\) and \(\{|+\rangle, |-\rangle\}\) are predefined. See the following Qiskit note.
Qiskit note: Computational Basis
qiskit.opflow module allows us to compute basic quantities using expressions very similar to the original methematical expressions. Here are the correspondence between mathematical expressions and opflow expression.
\(\ket{0} \quad \Rightarrow \quad\)
Zero
\(\ket{1} \quad \Rightarrow \quad\)One
\(\ket{+} \quad \Rightarrow \quad\)Plus
\(\ket{-} \quad \Rightarrow \quad\)Minus
The vector with “~” indicates bra. For example,
\(\bra{0} \quad \Rightarrow \quad\)
~One
The regular addition works.
\(\ket{0} + \ket{1} \quad \Rightarrow \quad\)
Zero + One
The operator for inner product is “@”. You need to evalute it with .eval().
\(\langle 0 | + \rangle \quad \Rightarrow \quad\)
(~Zero @ Plus).eval()
eval is a method associated with OperatorBase class in qiskit.opflow.
For more detail, see Qiskit API Document: qiskit.opflow
Qiskit Example 3.1.1 The orthonormality of the computational basis set is tested in Qiskit.
# Import numpy (for sqrt)
import numpy as np
# Import the base vectors from qiskit.opflow library
from qiskit.opflow import Zero, One, Plus, Minus
# Example of inner product calculation with qiskit
# First example calculate the norm of |0> and |1>
# Zero and One are ket
# ~Zero and ~One are corresponding bra
# @ product between bra and ket, that is inner product
# To complete the operation @, we must evaluate it by .eval()
Norm_of_Zero = np.sqrt((~Zero @ Zero).eval())
Norm_of_One = np.sqrt((~One @ One).eval())
# Show the reults
print("Norm of |0> =", Norm_of_Zero)
print("Norm of |1> =", Norm_of_One)
# Next we check the orthogonality between |0> and |1>
Inner_Product = (~Zero @ One).eval()
# Show the result.
print("<0|1> =", Inner_Product)
Norm of |0> = 1.0
Norm of |1> = 1.0
<0|1> = 0.0
Qiskit Example 3.1.2 Let us construct another orthonormal basis set \(|L\rangle = \frac{1}{\sqrt{2}}\left(|0\rangle + i |1\rangle\right)\) and \(|R\rangle = \frac{1}{\sqrt{2}}\left(|0\rangle - i |1\rangle\right)\). Notice the complex unit \(i\) on \(|1\rangle\).
# Let us try more complicated case.
# we will solve the above exercise problem using Qiskit
# import numpy
import numpy as np
# imaginary unit "i" is "1j" in python.
L = (Zero + 1j* One)/np.sqrt(2)
R = (Zero - 1j* One)/np.sqrt(2)
print( "<L|L> =",(~L@L).eval() )
print( "<R|R> =",(~R@R).eval() )
print( "<L|R> =",(~L @ R).eval() )
# Anser should be 0 since they are orthogonal.
<L|L> = (0.9999999999999998+0j)
<R|R> = (0.9999999999999998+0j)
<L|R> = 0j
Python note: Complex numbers
In python, a complex number is expressed as \(2 + 3j\). Note that symbol \(j\) is used instead of \(i\). The imaginary unit \(i\) is \(1j\). Notice \(1\) in from of \(j\). \(j\) must be used with a regular number. \(j\) alone causes an error.
Exercise 3.1.1
Confirm that base vectors
PlusandMinusare orthonormal using Qiskit.Calculate the inner product between
OneandMinusby hand and confirm your answer using Qiskit.
Bloch sphere#
While Eq. (3.1) can describe any qubit state, we can simplify it without losing generality. Writing the complex coefficient in the polar expression, \(c_0 = r_0 e^{i \phi_0}\) and \(c_1 = r_1 e^{i \phi_1}\) where \(r_i\) and \(\phi_i\) are modulus and argument. Then, we remove a global phase as
where \(\phi=\phi_1-\phi_0,\ \phi \in [0, 2\pi)\) and \(\simeq\) means “equivalent state vector”. Now, the normalization condition becomes \(r_0^2 + r_1^2 = 1\). Since \(r_0\) and \(r_1\) are positive, we can write them as \(r_0 = \cos\left(\frac{\theta}{2}\right)\) and \(r_1 = \sin\left(\frac{\theta}{2}\right)\) with \(0 < \theta < \pi\). Now the general qubit state is written as
This expression suggests that any pure state can be map to a point on the surface of a unit sphere using spherical coordinates \(\theta\) and \(\phi\). The north pole of the sphere (\(\theta=0\)) corresponds to \(\ket{0}\) and the south pole to \(\ket{1}\) (recall that the global phase \(e^{i \phi}\) can be omitted. When \(\theta = \frac{\pi}{2}\) and \(\phi=0\), we obtain \(|+\rangle\) and when \(\theta = \frac{\pi}{2}\) and \(\phi=\pi\), we have \(|-\rangle\).
The sphere is known as Bloch sphere and the arrow from the center of the sphere to the point on the surface is called Bloch vector.
Qiskit note: Bloch sphere
Qiskit provides four tools to visualize the Bloch sphere and vector.
Use
plot_bloch_vectorinqiskit.visuakizationif \(\theta\) and \(\phi\) are known.
plot_bloch_vector([r,theta,phi], coord_type='spherical', figsize=(w,h) )
API reference:plot_bloch_vector
Use
plot_bloch_multivectorif a state vector is known.
plot_bloch_multivector(state)
stateis a quantum state. Various format is allowed, including Statevector class objects. For other optional arguments.
API reference:plot_bloch_multivector
Use
drawmethod associated withstatevectorclass
psi
.draw('mpl')
where psi is astaetvectorclass object.mplspecifies the use ofmatplotlibmodule. This method is just a front end to plot-bloch-multivector.
API reference:Statevector.draw
We can even draw evolution of the Bloch vector as a movie using
visualize_transition.
visualize_transition(qc,fpg=50, spg=1) where
qcis a quantum circuit (I will explain it later.) See the following documentation for other parameters. API reference:visualize_transition
Qiskit Example 3.1.3 The following example plots the Bloch vectors of \(|0\rangle\), \(|1\rangle\), and \(|\pm\rangle\). To plot all of them at once, we need to use a tensor product of all vectors. In Qiskit, tensor product is done by “^”.
# Example of statevector
# import Statevector class
from qiskit.visualization import plot_bloch_multivector
# import basic state vectors
from qiskit.opflow import Zero, One, Plus, Minus
plot_bloch_multivector(Zero^One^Plus^Minus)
Qiskit Example 3.1.4 Plot the Bloch vectors of the states \(|L\rangle\) and \(|R\rangle\) discuessed in Qiskit Example 3.1.2.
plot_bloch_multivector(L^R)
Qiskit Example 3.1.5 A statevector is initially \(|0\rangle\). It is rotated around \(y\), \(z\), and \(x\) by angle $\frac{\pi}{2} for each rotation. It is done by rotation gates ry, rz, and rx. Construction of quantum circuits will be discussed later in great detail. The Bloch vector should come back to the starting point. See the animation.
%%capture
# The output block is disabled.
# load numpy and qiskit
import numpy as np
from qiskit import *
# create an empty quantum circuit
qr = QuantumRegister(1)
qc = QuantumCircuit(qr)
# add rotation gates to the circuit
qc.ry(np.pi/2,0)
qc.rz(np.pi/2,0)
qc.rx(np.pi/2,0)
# load the visdualization tool
from qiskit.visualization import visualize_transition
# generate a movie (it will be shown in next cell,
movie=visualize_transition(qc,fpg=50, spg=1)
# SHow the movie
movie